#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int maxn = 2e5 + 5, INF = 0x3f3f3f3f;
LL a[2][maxn], maxv1[2][maxn], maxv2[2][maxn];
bool v[2][maxn];

int main(){

    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);

    int T;
    cin >> T;
    while(T--){
        int n;
        cin >> n;
        for(int i = 0; i < 2; i++){
            for(int j = 1; j <= n; j++) cin >> a[i][j], v[i][j] = 0;
            maxv1[i][n + 1] = maxv2[i][n + 1] = -1e18;
            for(int j = n; j; j--){
                maxv1[i][j] = max(maxv1[i][j + 1], a[i][j] + j);
                maxv2[i][j] = max(maxv2[i][j + 1], a[i][j] - j);
            }
        }
        int x = 0, y = 1;
        v[0][1] = 1;
        LL ans = 1e18, t = 0;
        while(1){
            if (!v[x ^ 1][y]){
                LL tmp = max(t + n - y, n + 1 + maxv2[x][y + 1]);
                ans = min(ans, max(tmp + n - y + 1, maxv1[x ^ 1][y] - y + 1));
                x ^= 1;
            }
            else y++;
            if (y > n) break;
            v[x][y] = 1;
            t = max(t + 1, a[x][y] + 1);
        }
        cout << min(ans, t) << '\n';
    }

}